package top.xiesen.iterator;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class Test01 {


	public static void main(String[] args) {
		List list = new ArrayList();
		list.add("aaa");
		list.add("bbb");
		list.add("ccc");
		// 通过索引遍历
		for (int i = 0; i < list.size(); i++) {
			System.out.println(list.get(i));
		}
		// 通过迭代器遍历List
		Iterator iterator2 = list.iterator();
		while(iterator2.hasNext()){
			String str = (String) iterator2.next();
			System.out.println(str);
		}
		
		System.out.println("----------------");
		Set set = new HashSet();
		set.add("Allen");
		set.add("马哥");
		set.add("裴新");
		// 通过迭代器变了Set
		Iterator iterator = set.iterator();
		while(iterator.hasNext()){
			String str = (String) iterator.next();
			System.out.println(str);
		}
		
	}

}
